/**
 * 
 */
package edu.cmu.vlis.datamining.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jgrapht.alg.NeighborIndex;

import edu.cmu.vlis.datamining.core.Edge;
import edu.cmu.vlis.datamining.core.Feature;
import edu.cmu.vlis.datamining.core.FeatureList;
import edu.cmu.vlis.datamining.core.IFeatureCalculator;
import edu.cmu.vlis.datamining.core.Vertex;
import java.io.Serializable;
/**
 * This class represents a pair of nodes. A node is represented by
 * vertex. 
 */
public class NodePair implements Serializable{

    Vertex _a;
    Vertex _b;
    List<Feature> scores;
    
    public NodePair(Vertex a, Vertex b) {
        this._a = a;
        this._b = b;
    }

    public List<Feature> computeFeatures(NeighborIndex<Vertex, Edge> nIdx,Map<Vertex,Set<Integer>>cascadeFList){
        
        this.scores = new ArrayList<Feature>(5);
        for(IFeatureCalculator fc : (new FeatureList(nIdx,cascadeFList)).getFeatureList())
            scores.add(fc.compute(this._a, this._b));
        return scores;
    }
    
   
    
    public float getFeatureValOf(int feature){
        return (Float)(this.scores.get(feature).getValue());
    }
    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((_a == null) ? 0 : _a.hashCode());
        result = prime * result + ((_b == null) ? 0 : _b.hashCode());
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {

        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof NodePair))
            return false;
        NodePair other = (NodePair) obj;
        if (_a == null) {
            if (other._a != null)
                return false;
        } 
        if (_b == null) {
            if (other._b != null)
                return false;
        } 
        if(this._a.equals(other._a) && this._b.equals(other._b))
            return true;
        if(this._a.equals(other._b) && this._b.equals(other._a))
            return true;
        return false;
    }
}
